package top.withwings.bonus.common.pojo;

import java.beans.PropertyEditorSupport;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class UnixTimestampToDateEditor extends PropertyEditorSupport {


    @Override
    public void setAsText(String text) throws IllegalArgumentException {

        long timestamp = Long.parseLong(text);

        Date date = new Date();

        date.setTime(timestamp);

        setValue(date);
    }

    @Override
    public String getAsText() {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = (Date) getValue();
        return dateFormat.format(date);
    }

}
